package com.rock.common.plugin;

import com.alibaba.druid.util.DruidPasswordCallback;
import com.rock.common.util.AESUtil;
import org.apache.commons.lang3.StringUtils;
import java.util.Properties;

/**
 * 解密数据库连接用户密码
 * 
 * @Description:TODO
 * @author: hotdog
 * @date: 2018年8月17日 下午3:56:36
 * @Copyright: v1.0
 *
 */
public class DBPasswordCallback extends DruidPasswordCallback {

	private static final long serialVersionUID = 1L;

	@Override
	public void setProperties(Properties properties) {
		super.setProperties(properties);
		String pwd = properties.getProperty("password");
		if (StringUtils.isNoneBlank(pwd)) {
			try {
				// 这里的password是将jdbc.properties配置得到的密码进行解密之后的值
				// 所以这里的代码是将密码进行解密
				// TODO 将pwd进行解密;
				String password = AESUtil.getInstance().decrypt(pwd);
				setPassword(password.toCharArray());
			} catch (Exception e) {
				setPassword(pwd.toCharArray());
			}
		}
	}
}